#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
调试OCR引擎
"""

import sys
import os

# 添加项目根目录到Python路径
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

def debug_ocr():
    """调试OCR引擎"""
    print("开始调试OCR引擎...")
    
    # 延迟导入以避免重复初始化
    from ocr.ocr_engine import OCREngine
    
    # 创建OCR引擎实例
    ocr_engine = OCREngine()
    
    # 检查模型是否成功初始化
    if ocr_engine.model is None:
        print("错误: OCR引擎初始化失败")
        return
    
    # 测试图像识别
    image_path = os.path.join("ocr", "1.png")  # 使用正确的路径
    if os.path.exists(image_path):
        print(f"正在识别图像: {image_path}")
        
        # 测试基本识别功能
        try:
            result = ocr_engine.recognize(image_path)
            print(f"识别结果: {result}")
        except Exception as e:
            print(f"识别过程中发生错误: {e}")
    else:
        print(f"测试图像 {image_path} 不存在")

if __name__ == "__main__":
    debug_ocr()